package com.yunhe.java.pro11JiHe;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Administrator on 2017/8/4 0004.
 */
public class Teacher {
    private String name;
    private int id;
    static List courseList;
    static Scanner sc;
    static{
        courseList=new ArrayList();
        sc=new Scanner(System.in);
    }

   //添加课程
    public void courseAdd(){
        System.out.println("********************************课程信息录入*****************************");
        while(true) {
            System.out.print("请输入课程编号：");
            int i = sc.nextInt();
            System.out.print("请输入课程名称：");
            String name = sc.next();
            Course course = new Course(i, name);
            courseList.add(course);
            System.out.print("是否继续添加（y/n):");
            String j = sc.next();
            if (j.equals("n")) {
                break;
            }
        }
        showCourse();
        operation();
    }

    //删除课程
    public void courseDelete(){
        System.out.println("***************************课程删除***************************");
        System.out.print("请输入要删除课程编号：");
        int i=sc.nextInt();
        courseList.remove(i-1);
        System.out.println("删除成功！");
        showCourse();
        operation();
    }

    //修改课程
    public void courseSet(){
        System.out.println("***************************课程修改***************************");
        System.out.print("请输入要修改课程编号：");
        int i=sc.nextInt();
        System.out.print("请输入修改后课程名称：");
        String name=sc.next();
        courseList.set(i-1,new Course(i,name));

        System.out.println("修改成功！");
        showCourse();
        operation();
    }


    //展示课程
    public void showCourse(){
        System.out.println("***************************课程列表***************************");
        for(Object obj:courseList){
            Course course=(Course)obj; //object强转成course
            System.out.println(course.getId()+"."+course.getName());
        }
    }


    //课程操作
    public void operation(){
        System.out.println("1.添加课程 2.删除课程 3.修改课程");
        System.out.print("请输入操作序号：");
        int i=sc.nextInt();
        switch (i){
            case 1:courseAdd();
            case 2:courseDelete();
            case 3:courseSet();
            default:showCourse();
        }
    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

}
